package com.situ.admin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.admin.bean.User;
import com.situ.admin.mapper.UserMapper;
import com.situ.admin.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;

	@Override
	public PageInfo getByPage(Integer page, Integer limit, User user) {
		if (page == null) {
			page = 1;
		}
		if (limit == null) {
			List list = userMapper.select(user);
			limit = list.size();
		}
		PageHelper.startPage(page, limit);
		List list = userMapper.select(user);
		PageInfo pageInfo = new PageInfo<>(list);
		return pageInfo;
	}

	@Override
	public User remove(Integer id) {
		User user = userMapper.selectByPrimaryKey(id);

		if (user.getStatus() == 0) {
			user.setStatus(1); // 软删除
		} else if (user.getStatus() == 1) {
			user.setStatus(0);
		}
		userMapper.updateByPrimaryKey(user);
		return user;
	}

}
